from Base.Base import Base
from selenium.webdriver.common.by import By
import time
# 页面类
class Page1(Base):
    # 1.输入框输入
    search_loc = (By.XPATH, '//*[@id="kw"]')
    def search(self):
        self.send_keys(self.search_loc, 'python')
    # 2.点击百度一下
    dianji_loc = (By.XPATH, '//*[@id="su"]')

    def dianji(self):
        self.click(self.dianji_loc)
    # 3.点击请登录按钮
    login_loc=(By.XPATH,'//*[@id="u"]/a[3]')
    def login(self):
        self.click(self.login_loc)
    # 断言1 账号登录
    dy1_loc=(By.ID,'TANGRAM__PSP_11__changePwdCodeItem')
    def dy1(self):
        return self.text(self.dy1_loc)
    # 4.输入用户名和密码
    username_loc=(By.XPATH,'//*[@id="TANGRAM__PSP_11__userName"]')
    def username(self):
        self.send_keys(self.username_loc,'zzd19525482253')
    # 5.输入密码
    password_loc=(By.XPATH,'//*[@id="TANGRAM__PSP_11__password"]')
    def password(self):
        self.send_keys(self.password_loc,'zzd040708')
    # 6.勾选协议
    xieyi_loc=(By.XPATH,'//*[@id="TANGRAM__PSP_11__isAgree"]')
    def xieyi(self):
        self.click(self.xieyi_loc)
    # 7.点击登录按钮
    login1_loc=(By.ID,'TANGRAM__PSP_11__submit')
    def login1(self):
        self.click(self.login1_loc)
    # 8.回到首页
    home_loc=(By.XPATH,'/html/body/div[3]/div[1]/div/div[2]/a[1]')
    def home(self):
        self.click(self.home_loc)
    # 断言2 百度热搜
    dy2_loc=(By.XPATH,'//*[@id="s_mod_weather"]/div[1]/a/div/span[1]/span')
    def dy2(self):
        return self.text(self.dy2_loc)



    # 业务逻辑
    def luoji_baidu_01_login(self):
        # 打开网址
        self.open_url('https://www.baidu.com/')
        # 1.输入框输入
        self.search()
        # 2.点击百度一下
        self.dianji()
        # 3.点击请登录按钮
        self.login()
        # 断言1 账号登录
        print(self.dy1())
        assert "账号登录" in self.dy1()
        # 4.输入用户名
        self.username()
        # 5.输入密码
        self.password()
        # 6.勾选协议
        self.xieyi()
        # 7.点击登录按钮
        self.login1()
        #切换窗口
        self.handles()
        # 8.回到首页
        self.home()
        # 断言2 我的关注
        print(self.dy2())
        assert "昌平" in self.dy2()
        time.sleep(5)

